package com.xiaojimao.gr_user.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaojimao.gr_user.Mapper.UserMapper;
import com.xiaojimao.gr_user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDao extends ServiceImpl<UserMapper, User> {

    @Autowired
    private UserMapper userMapper;

    public User getUser(String userName) {
        return lambdaQuery()
                .eq(User::getUserName, userName)
                .one();
    }

    public void setStatus(String id, String status) {
        lambdaUpdate()
                .eq(User::getId, id)
                .set(User::getStatus, status)
                .update();
    }

    public void setPermission(String id, String permission) {
        lambdaUpdate()
                .eq(User::getId, id)
                .set(User::getPermission, permission)
                .update();
    }

    public IPage<User> list(Page<User> page) {
        LambdaQueryWrapper<User> query = Wrappers.lambdaQuery();
        return userMapper.selectPage(page, query);
    }

}
